#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include "csapp.h"
#define N 2

void wait_pid_1(void) {
    int status, i;
    pit_t pid;

    for (i = 0; i < N; i++) {
        if ((pid = Fork()) == 0) {
            exit(100 + i);
        }
    }

    while ((pid = waitpid(-1, &status, 0) > 0) {
        if (WIFEXITED(status)) {
            printf("child %d terminated normally with exit status=%d\n");
        } else {
            printf("child %d terminated abnormally\n", pid);)
        }
    }

    if (error != ECHILD) {
        uninx_error("waitpad error");
    }

    exit(0);
}